<?php

namespace Xrfg\Api\Trading\Spot\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Xrfg\Core\Trading\Spot\Models\Order;

class OrderRequest extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        $rules = [
            'symbol' => [
                'required',
            ],
            'side' => [
                'required',
                Rule::in([
                    Order::SIDE_BUY,
                    Order::SIDE_SELL,
                ]),
            ],
            'order_type' => [
                'required',
                Rule::in([
                    Order::TYPE_LIMIT,
                    Order::TYPE_MARKET,
                ]),
            ],
            'number' => [
                'required',
                'numeric',
                'gt:0',
                'number_decimals:'.$this->input('order_type').','.$this->input('symbol'),
            ],
        ];

        if (Order::TYPE_LIMIT == $this->input('order_type')) {
            $rules['price'] = [
                'required',
                'numeric',
                'gt:0',
                'price_decimals:'.$this->input('order_type').','.$this->input('symbol'),
            ];
        }

        return $rules;
    }
}
